package com.trade.wzj.common.yang;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.trade.wzj.model.xiang.ClientQuota;
import com.trade.wzj.model.xiang.ClientQuotaDetails;
import com.trade.wzj.service.yang.ClientInfoQuotaServiceYang;

@Controller
@RequestMapping("/ClientInfoQuotaControllerYang")
public class ClientInfoQuotaControllerYang {

	@Resource(name="clientInfoQuotas")
	private ClientInfoQuotaServiceYang clientInfoQuotaServiceYang;

	public ClientInfoQuotaServiceYang getClientInfoQuotaServiceYang() {
		return clientInfoQuotaServiceYang;
	}

	public void setClientInfoQuotaServiceYang(ClientInfoQuotaServiceYang clientInfoQuotaServiceYang) {
		this.clientInfoQuotaServiceYang = clientInfoQuotaServiceYang;
	}


	/**
	 * 根据客户名称模糊查询客户报价单（包括报价详情单、商品信息、客户信息、付款类型）
	 * @param clientName 客户名称
	 * @param currentPages 页码
	 * @return
	 */
	@RequestMapping("/findClientQuota")
	@ResponseBody
	public PageInfo<ClientQuota> findClientQuota(
			@RequestParam(value = "clientName", required = false) String clientName,
			@RequestParam(value = "currentPages", required = false) Integer currentPages) {
		// 起始页数
		Integer currentPage = 1;
		// 每条显示的行数
		int rowPerPage = 5;
		PageInfo<ClientQuota> pageInfo = null;
		// 结果集列表
		List<ClientQuota> list = null;
		try {
			if (null != currentPages) {
				// 页码不为空时，将当前页信息赋值
				currentPage = currentPages;
			}
			PageHelper.startPage(currentPage, rowPerPage);
			list = clientInfoQuotaServiceYang.findClientQuota(clientName);

			pageInfo = new PageInfo<ClientQuota>(list);

			System.out.println(list.size());
			System.out.println(pageInfo.getList());
			for (ClientQuota clientQuota : list) {
				System.out.println(clientQuota);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return pageInfo;
	}
	
	
	@RequestMapping("/findClientQuotaById")
	@ResponseBody
	public PageInfo<ClientQuota> findClientQuotaById(
			@RequestParam(value = "id", required = true) Integer id,
			@RequestParam(value = "currentPages", required = false) Integer currentPages) {
		// 起始页数
		Integer currentPage = 1;
		// 每条显示的行数
		int rowPerPage = 5;
		PageInfo<ClientQuota> pageInfo = null;
		// 结果集列表
		List<ClientQuota> list = null;
		try {
			if (null != currentPages) {
				// 页码不为空时，将当前页信息赋值
				currentPage = currentPages;
			}
			PageHelper.startPage(currentPage, rowPerPage);
			list = clientInfoQuotaServiceYang.findClientQuotaById(id);

			pageInfo = new PageInfo<ClientQuota>(list);

			System.out.println(list.size());
			System.out.println(pageInfo.getList());
			for (ClientQuota clientQuota : list) {
				System.out.println(clientQuota);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return pageInfo;
	}
	
	
	@RequestMapping("/getClientDetailPriceById")
	@ResponseBody
	public PageInfo<ClientQuotaDetails> getClientDetailPriceById(@RequestParam(value="id",required=false)Integer id,@RequestParam(value="currentPages",required=false)Integer currentPages,@RequestParam(value="productName",required=false)String productName){
		// 起始页数
		Integer currentPage = 1;
		// 每条显示的行数
		int rowPerPage = 5;
		PageInfo<ClientQuotaDetails> pageInfo = null;
		// 结果集列表
		List<ClientQuotaDetails> list = null;
		
		
		try {
			if (null != currentPages) {
				// 页码不为空时，将当前页信息赋值
				currentPage = currentPages;
			}
			PageHelper.startPage(currentPage, rowPerPage);
			list = clientInfoQuotaServiceYang.getClientDetailPrice(id,productName);

			pageInfo = new PageInfo<ClientQuotaDetails>(list);

		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return pageInfo;
	}
	
	@RequestMapping("/getListClientProduct")
	@ResponseBody
	public List<ClientQuotaDetails> getListClientProduct(@RequestParam(value="clientInfoId",required=false)Integer clientInfoId,@RequestParam(value="productId",required=false)Integer[] productId){
		
		List<ClientQuotaDetails> list = null;
		try {
			list=clientInfoQuotaServiceYang.getProducts(clientInfoId,productId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}
	
	//查询所有客户报价信息，可按照客户名称查询
	@RequestMapping("/getAllClientPriceList")
	@ResponseBody
	public PageInfo<ClientQuota> getAllClientPriceList(
												   @RequestParam(value="currentPages",required=false)Integer currentPages,
												   @RequestParam(value="clientName",required=false)String clientName){
		// 起始页数
		Integer currentPage = 1;
		// 每条显示的行数
		int rowPerPage = 5;
		PageInfo<ClientQuota> pageInfo = null;
		// 结果集列表
		List<ClientQuota> list = null;
		if (null != currentPages) {
			// 页码不为空时，将当前页信息赋值
			currentPage = currentPages;
		}
		try {
			PageHelper.startPage(currentPage, rowPerPage);
			list = clientInfoQuotaServiceYang.getAllClientPriceList(clientName);

			pageInfo = new PageInfo<ClientQuota>(list);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return pageInfo;
	}
}
